package com.final_project.zombiemenace.settings;

import java.io.File;

import com.final_project.zombiemenace.MainMenuActivity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class Settings {
	private static final String SETTINGS_FILE_NAME = "settings";
	private Context context;
	private SharedPreferences settingsFile;
	private Editor settingsEditor;

	public Settings(Context context) {
		this.context = context;
		settingsFile = context.getSharedPreferences(SETTINGS_FILE_NAME,
				Context.MODE_PRIVATE);
		settingsEditor = settingsFile.edit();
		initializeDefaultHighScoreSharedPreferences();
	}

	/**
	 * Initialize shared preference file if it doesn't exist with default
	 * values.The file doesn't exits if the Applications is not installed or
	 * installed and not started
	 */
	@SuppressLint("SdCardPath")
	private void initializeDefaultHighScoreSharedPreferences() {
		File f = new File("/data/data/" + context.getPackageName()
				+ "/shared_prefs/settings.xml");
		if (!f.exists()) {
			settingsEditor.putBoolean("Vibration", true);
			settingsEditor.putBoolean("Mute", false);
			settingsEditor.putFloat("Volume", 50);
			settingsEditor.commit();
		}
	}

	public boolean getIsGoingToVibrateFromSharedPrefs(){
		return settingsFile.getBoolean("Vibration", true);
	}

	public boolean getIsMutedFromSharedPrefs(){
		return settingsFile.getBoolean("Mute", false);
	}

	public float getVolumeFromSharedPrefs(){
		return settingsFile.getFloat("Volume", 50);
	}
	
	
	public void writeSettingsToFile(){
		settingsEditor.putBoolean("Vibration", MainMenuActivity.vibration);
		settingsEditor.putBoolean("Mute", MainMenuActivity.isMuted);
		settingsEditor.putFloat("Volume", MainMenuActivity.musicVolume);
		settingsEditor.commit();		
	}
}
